Loading images from the file system

You can create textures from images in Kanzi Studio or load and use images in your Kanzi application from the file system of the device where you run the application.

To load images from the file system:

  1. In Kanzi Studio create a project using the Application template.
  2. In the Project create a node on which you want show a texture and in the Properties set the Material property to a material that supports textures. See Using material types and Using materials.
    For example, in the Project create a Box node and in the Properties set Material to VertexPhongTexturedMaterial.
  3. In the Project select the node you created in the previous step, in the Properties add the Texture property, and set it to a resource ID.
    For example, set the Texture property to the resource ID BoxTexture.
    This way you assign to the Texture property a resource ID which you later use to show a texture.
  4. In the Project press Alt and right-click the node you created and select Alias. See Using aliases.
    Kanzi Studio creates an alias pointing to the node from which you created the alias and adds it to the resource dictionary of its nearest ancestor node that contains a resource dictionary.
    Use an Alias to get consistent access to a Kanzi node. You can use aliases to access nodes both in Kanzi Studio and using the Kanzi Engine API or scripting.
  5. In Kanzi Studio select File > Export > Export KZB.
    Kanzi Studio creates the kzb file and configuration files from your Kanzi Studio project. Kanzi Studio stores the exported files in <KanziWorkspace>/Projects/<ProjectName>/Application/bin or the location you specify in the Binary Export Directory property in Project > Properties. The kzb file contains all nodes and resources from your Kanzi Studio project, except the resources you mark in a localization table as locale packs.
    When you run your Kanzi application from Visual Studio, your Visual Studio solution reads these files to create your Kanzi application.
  6. Place the image you want to use in the texture to <ProjectName>/Application/bin.
  7. In Visual Studio open the Visual Studio solution for your application located in Application/configs/platforms/win32. In the C++ application load the texture.
    // In the main class of the application use the onProjectLoaded()
    // virtual function to load a file from the file system.
    virtual void onProjectLoaded()
    {
        // Get the Screen node of your application.
        ScreenSharedPtr screenNode = getScreen();
        // Get the Box node using the #Box alias.
        Model3DSharedPtr box = screenNode->lookupNode<Model3D>("#Box");
        // Load the texture from the <ProjectName>/Application/bin directory.
        box->addResource(ResourceID("BoxTexture"), "file://./Red.png");
    }
  8. In Visual Studio select one of the solution configurations for your version of Visual Studio and run your application.
    For example, if you are still developing your application, select the GL_vs2015_Debug configuration. If you want to create a production version of your Kanzi application, select one of the available release configurations.

    When you launch the application, Kanzi loads the image stored in <KanziWorkspace>/Projects/<ProjectName>/Application/bin and creates a texture from the image. When Kanzi loads the application kzb file, it sets the texture to the node you get in the onProjectLoaded function.

See also

Textures

Using material types

Using materials

Using aliases

Using kzb files

API reference